package setting

import (
	"context"
	"fmt"
	"github.com/redis/go-redis/v9"
	"gopkg.in/ini.v1"
)

var RDB *redis.Client

func initRedisClient(config *ini.File) error {
	section := config.Section("redis")
	redisOpt, err := redis.ParseURL(section.Key("uri").String())
	if err != nil {
		return fmt.Errorf("failed to parse redis uri: %w", err)
	}
	RDB = redis.NewClient(redisOpt)
	err = RDB.Ping(context.Background()).Err()
	if err != nil {
		return fmt.Errorf("failed to ping redis client: %w", err)
	}
	return nil
}
